﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PercentCalculation
{
    class Program
    {
        const int monthInYear = 12;

        static void Main(string[] args)
        {
            string repeat = "Y";
            
            while (repeat == "Y")
            {
                CalculateCreditPayment();
                Console.WriteLine("Do you want to calculate one more payment? Y/N");
                repeat = Console.ReadLine();
            }
        }

        static double CreditBodyMonthCalculation(double creditBodyAll, double creditPercent, double numberOfMonth)
        {
            return creditBodyAll / (numberOfMonth);
        }

        static double NumberOfMonth( double numberOfYears)
        {
            return numberOfYears * monthInYear;
        }

        static double RestOfCreditBody( double creditBodyAll, double creditBodyMonth, double currentMonth)
        {
            return creditBodyAll - currentMonth * creditBodyMonth;
        }

        static double CurrentMonthPercent(double restOfCreditBody, double creditPercent)
        {
            return ( restOfCreditBody * creditPercent / 100 ) / monthInYear;
        }

        static double CurrentMonthCreditPayment(double creditBodyMonth, double currentMonthPercent)
        {
            return creditBodyMonth + currentMonthPercent;
        }

        static void CalculateCreditPayment()
        {
            double creditBodyAll = 0;
            double creditPercent = 0;
            double numberOfYears = 0;
            double creditBodyMonth = 0;
            double numberOfMonth = 0;
            double restOfCreditBody = 0;
            double currentMonthPercent = 0;
            double currentMonthCreditPayment = 0;
            double creditPaymentAll = 0;

            Console.WriteLine("Calculation of complex percent");
            Console.WriteLine("Please, enter credit body:");
            creditBodyAll = Double.Parse(Console.ReadLine());
            Console.WriteLine("Please, enter % of credit:");
            creditPercent = Double.Parse(Console.ReadLine());
            Console.WriteLine("Please, enter number of years:");
            numberOfYears = Double.Parse(Console.ReadLine());

            numberOfMonth = NumberOfMonth(numberOfYears);
            creditBodyMonth = CreditBodyMonthCalculation(creditBodyAll, creditPercent, numberOfMonth);

            for (int currentMonth = 0; currentMonth < numberOfMonth; currentMonth++)
            {
                restOfCreditBody = RestOfCreditBody(creditBodyAll, creditBodyMonth, currentMonth);
                currentMonthPercent = CurrentMonthPercent(restOfCreditBody, creditPercent);
                currentMonthCreditPayment = CurrentMonthCreditPayment(creditBodyMonth, currentMonthPercent);
                creditPaymentAll = creditPaymentAll + currentMonthCreditPayment;
            }
            Console.WriteLine("Your credit payment will be: {0}", creditPaymentAll);
        }
       }
}
